package com.android.djlmapp.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.Html;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.android.djlmapp.R;
import com.android.djlmapp.html.URLImageGetter;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;

import static com.android.djlmapp.application.UILOption.options;

/**
 * 首页公告弹窗
 */
public class GongGaoDialog extends Dialog {
    private Activity mContext;
    private String str;
    private TextView tv_content;

    public GongGaoDialog(Activity context, String str) {
        super(context, R.style.BtDialogStyle);
        this.mContext = context;
        this.str = str;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.item_tabhomedialog);
        Button btn_dis = (Button) findViewById(R.id.btn_dis);
        tv_content = (TextView) findViewById(R.id.tv_content);

        options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.mipmap.data_load_error)
                .showImageForEmptyUri(R.mipmap.data_load_error)
                .showImageOnFail(R.mipmap.data_load_error)
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .considerExifParams(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .displayer(new FadeInBitmapDisplayer(300))
                .build();
        CharSequence charSequence = Html.fromHtml(str, new URLImageGetter(str, mContext, tv_content, options), null);
        tv_content.setText(charSequence);

        btn_dis.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.gravity = Gravity.CENTER;
        window.setAttributes(params);
    }
}